package com.bottomlord.reactice.streams;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

/**
 * @author ChenYue
 * @date 2021/3/31 22:32
 */
public class SubscriptionAdapter<T> implements Subscription {
    private final DecoratingSubscriber<? super T> subscriber;

    public SubscriptionAdapter(Subscriber<? super T> subscriber) {
        this.subscriber = new DecoratingSubscriber<>(subscriber);
    }

    @Override
    public void request(long n) {
        if (n < 1) {
            throw new IllegalArgumentException("The number of elements to requests must be more than zero!");
        }
        this.subscriber.setMaxRequest(n);
    }

    @Override
    public void cancel() {
        this.subscriber.cancel();
    }

    public Subscriber<? super T> getSubscriber() {
        return subscriber;
    }

    public Subscriber<? super T> getSourceSubscriber() {
        return subscriber.getSource();
    }
}
